package com.fz.us.oa.web.controller.com;

import com.fz.us.admin.base.bean.search.SearchEnum;
import com.fz.us.admin.base.bean.search.order.Order;
import com.fz.us.admin.base.bean.search.result.SearchResultList;
import com.fz.us.admin.base.bean.search.result.SearchResultPaging;
import com.fz.us.admin.base.bean.search.rule.Rule;
import com.fz.us.admin.base.bean.search.rule.RuleHelper;
import com.fz.us.admin.base.utils.DataUtil;
import com.fz.us.admin.company.bean.FlowEnum;
import com.fz.us.admin.company.entity.TaskEntity;
import com.fz.us.admin.company.entity.User;
import com.fz.us.admin.dict.entity.Dict;
import com.fz.us.admin.dict.entity.DictItem;
import com.fz.us.base.bean.BaseEnum;
import com.fz.us.oa.core.entity.com.*;
import com.fz.us.oa.core.entity.common.FileManage;
import com.fz.us.oa.core.service.com.*;
import com.fz.us.oa.web.controller.BaseController;
import com.fz.us.oa.web.shiro.bind.annotation.CurrentUser;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;

/**
 * Created by dzw on 2018/3/13.
 * 人员信息表 和 统计汇总功能
 */
@Controller
@RequestMapping("/com/person")
public class PersonController extends BaseController {
    private static final long serialVersionUID = 3959913017848888419L;

    @Autowired
    private PersonService personService;
    @Autowired
    private DirectorService directorService;
    @Autowired
    private ResidentService residentService;
    @Autowired
    private StudyService studyService;
    @Autowired
    private WorkService workService;
    @Autowired
    private FamilyService familyService;

    /**
     * 列表
     * @param viewtype 1：人员总表（显示2018换届后有内容的数据）
     *                 2：居民区书记 换届前
     *                 3：居民区书记 换届后
     *                 4：备选书记 换届前
     *                 5：主任信息 换届前
     *                 6：主任信息 换届后
     */
    @RequestMapping(value = "list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String, Object> list(@CurrentUser User user, String viewtype, String streetId){

        DictItem personNature = getShuJiHouBei(); //书记后备
        DictItem generalBefore = getGeneralBefore(); //换届前（2015-2018）
        DictItem generalAfter = getGeneralAfter(); //换届后（2018-2021）


        List<DictItem> hasStreetList = new ArrayList<DictItem>();
        if(StringUtils.isNotEmpty(user.getStreetIds())){
            for(String sid:user.getStreetIds().split(",")){
                hasStreetList.add(dictItemService.get(sid.trim()));
            }
        }

        Order order = Order.order("createTime", SearchEnum.OrderType.desc);
        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("state", BaseEnum.StateEnum.Enable));
        rules.add(RuleHelper.in("street", hasStreetList)); //根据街道权限
        if(StringUtils.isNotEmpty(streetId)){
            rules.add(RuleHelper.eq("street", dictItemService.get(streetId)));
        }

        SearchResultPaging searchResult = null;
        if("1".equals(viewtype)){
            //人员总表
            rules.add(RuleHelper.eq("generalDict", generalAfter));
            searchResult = personService.paging(null,rules,order,"com.fz.us.oa.core.entity.com.Person",
                    new FlowEnum.ProcessState[]{FlowEnum.ProcessState.Finished, FlowEnum.ProcessState.Running, FlowEnum.ProcessState.Backed}, null);

        }else if("2".equals(viewtype)){
            //居民区书记 换届前
            rules.add(RuleHelper.ne("personNature", personNature));
            rules.add(RuleHelper.eq("generalDict", generalBefore));
            searchResult = personService.paging(null,rules,order,"com.fz.us.oa.core.entity.com.Person",
                    new FlowEnum.ProcessState[]{FlowEnum.ProcessState.Finished, FlowEnum.ProcessState.Running, FlowEnum.ProcessState.Backed}, null);

        }else if("3".equals(viewtype)){
            //居民区书记 换届后
            rules.add(RuleHelper.ne("personNature", personNature));
            rules.add(RuleHelper.eq("generalDict", generalAfter));
            searchResult = personService.paging(null,rules,order,"com.fz.us.oa.core.entity.com.Person",
                    new FlowEnum.ProcessState[]{FlowEnum.ProcessState.Finished, FlowEnum.ProcessState.Running, FlowEnum.ProcessState.Backed}, null);

        }else if("4".equals(viewtype)){
            //备选书记 换届前
            rules.add(RuleHelper.eq("personNature", personNature));
            rules.add(RuleHelper.eq("generalDict", generalBefore));
            searchResult = personService.paging(null,rules, order,"com.fz.us.oa.core.entity.com.Person",
                    new FlowEnum.ProcessState[]{FlowEnum.ProcessState.Finished, FlowEnum.ProcessState.Running, FlowEnum.ProcessState.Backed}, null);

        }else if("5".equals(viewtype)){
            //主任信息 换届前
//            rules.add(RuleHelper.isNotNull("resident"));
            searchResult = directorService.paging(null,rules,order,"com.fz.us.oa.core.entity.com.Director",
                    new FlowEnum.ProcessState[]{FlowEnum.ProcessState.Finished, FlowEnum.ProcessState.Running, FlowEnum.ProcessState.Backed}, null);

        }else if("6".equals(viewtype)){
            //主任信息 换届后
//            rules.add(RuleHelper.isNotNull("resident1"));
            searchResult = directorService.paging(null,rules,order,"com.fz.us.oa.core.entity.com.Director",
                    new FlowEnum.ProcessState[]{FlowEnum.ProcessState.Finished, FlowEnum.ProcessState.Running, FlowEnum.ProcessState.Backed}, null);

        }

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String, Object> rMap;

        if("5".equals(viewtype) || "6".equals(viewtype)){ //主任信息
            List<Director> directorList = searchResult.getList();
            for(Director director:directorList){
                rMap = new HashMap<String, Object>();
                rMap.put("id", director.getId());
                rMap.put("area", StringUtils.isNotEmpty(director.getArea()) ? director.getArea() : "");
                rMap.put("street", director.getStreet()!=null ? director.getStreet().getName() : "");
                rMap.put("name", StringUtils.isNotEmpty(director.getName()) ? director.getName() : "");
                rMap.put("gender", StringUtils.isNotEmpty(director.getGender()) ? director.getGender() : "");
                rMap.put("highEdu", director.getHighEdu()!=null ? director.getHighEdu().getName() : "");
                rMap.put("personNature", director.getPersonNature()!=null ? director.getPersonNature().getName() : "");
                rMap.put("shoulder", director.getShoulder()==1?"是":"否");
                rMap.put("resident", director.getResident()!=null?director.getResident().getName():"");
                rMap.put("state", director.getProcessState().value());
                rMap.put("age", getAge(director.getBirthday()));
                rMap.put("isDirector", 1);
                dataRows.add(rMap);
            }
        }else{ //普通的
            List<Person> personList = searchResult.getList();
            for(Person person:personList){
                rMap = new HashMap<String, Object>();
                rMap.put("id", person.getId());
                rMap.put("area", StringUtils.isNotEmpty(person.getArea()) ? person.getArea() : "");
                rMap.put("street", person.getStreet()!=null ? person.getStreet().getName() : "");
                rMap.put("name", StringUtils.isNotEmpty(person.getName()) ? person.getName() : "");
                rMap.put("gender", StringUtils.isNotEmpty(person.getGender()) ? person.getGender() : "");
                rMap.put("highEdu", person.getHighEdu()!=null ? person.getHighEdu().getName() : "");
                rMap.put("personNature", person.getPersonNature() !=null ? person.getPersonNature().getName() : "");
                rMap.put("shoulder", person.getShoulder() ==1?"是":"否");
                rMap.put("resident", person.getResident() !=null?person.getResident().getName():"");
                rMap.put("state", person.getProcessState().value());
                rMap.put("age", getAge(person.getBirthday()));
                rMap.put("isDirector", 0);
                dataRows.add(rMap);
            }
        }


        data.put("dataRows", dataRows);
        data.put("page", searchResult.getPageNumber());
        data.put("rows", searchResult.getPageSize());
        data.put("records", searchResult.getTotalCount());
        data.put("total", searchResult.getPageCount());
        return data;
    }

    /**
     * 新建编辑页面
     */
    @RequestMapping(value = "input", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String input(@CurrentUser User user, Model model, String keyId, Integer isDirector, String draft, String index, String todo, String remind, String record, String viewtype){
        if(StringUtils.isNotEmpty(keyId)){
            if(isDirector!=null && isDirector==1){
                Director director = directorService.get(keyId);
                model.addAttribute("person", director);
            }else{
                Person person = personService.get(keyId);
                model.addAttribute("person", person);
            }
        }
        if(isDirector!=null && isDirector==1){
            model.addAttribute("personNatureDict", getDictItems(user, "directorPersonNature")); //主任人员性质
        }else{
            model.addAttribute("personNatureDict", getDictItems(user, "personNature")); //人员性质
        }

        if("1".equals(viewtype) || "3".equals(viewtype)){ //总换届后视图中进入的
            model.addAttribute("general", "after");
        }else{
            model.addAttribute("general", "before");
        }
        model.addAttribute("nationDict", getDictItems(user, "nation")); //民族
        model.addAttribute("workNatureDict", getDictItems(user, "workNature")); //工作性质
        model.addAttribute("eduDict", getDictItems(user, "edu")); //最高学历
        model.addAttribute("streetDict", getDictItems(user, "street")); //所在街道
        model.addAttribute("draft", draft);
        model.addAttribute("index", index);
        model.addAttribute("todo", todo);
        model.addAttribute("remind", remind);
        model.addAttribute("record", record);
        model.addAttribute("isDirector", isDirector);

        return "/com/person_input";
    }

    /**
     * 只读页面
     */
    @RequestMapping(value = "read", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String read(@CurrentUser User user, Model model, String keyId, Integer isDirector, String viewtype, String draft, String index, String todo, String remind, String record){
        if(StringUtils.isNotEmpty(keyId)){
            if(isDirector!=null && isDirector==1){
                Director director = directorService.get(keyId);
                model.addAttribute("person", director);

                List<Study> studyList = new ArrayList<Study>();
                for(Study study:director.getStudyList()){
                    if("Enable".equals(study.getState().name())){
                        studyList.add(study);
                    }
                }
                List<Work> workList = new ArrayList<Work>();
                for(Work work:director.getWorkList()){
                    if("Enable".equals(work.getState().name())){
                        workList.add(work);
                    }
                }
                model.addAttribute("workList", workList);
                model.addAttribute("studyList", studyList);

            }else{
                Person person = personService.get(keyId);
                if (person!=null){
                    model.addAttribute("person", person);

                    List<Study> studyList = new ArrayList<Study>();
                    for(Study study:person.getStudyList()){
                        if("Enable".equals(study.getState().name())){
                            studyList.add(study);
                        }
                    }

                    List<Work> workList = new ArrayList<Work>();
                    for(Work work:person.getWorkList()){
                        if("Enable".equals(work.getState().name())){
                            workList.add(work);
                        }
                    }

                    model.addAttribute("workList", workList);
                    model.addAttribute("studyList", studyList);
                }else{
                    model.addAttribute("xinxi", "没有数据");
                }

            }
            TaskEntity taskEntity = taskEntityService.getInfoByKeyId(keyId);
            int stepNo = taskEntity.getStepNo();
            String isEdit = isEdit(keyId);
            model.addAttribute("stepNo", stepNo);
            model.addAttribute("isEdit", isEdit);
        }
        model.addAttribute("draft", draft);
        model.addAttribute("index", index);
        model.addAttribute("todo", todo);
        model.addAttribute("remind", remind);
        model.addAttribute("record", record);
        model.addAttribute("isDirector", isDirector);
        model.addAttribute("viewtype", viewtype);

        return "/com/person_read";
    }

    /**
     * 赋值数据
     */
    public Person setData(User user, String keyId, String name, String gender, String birthday, String nationId, String origin, String birthPlace, String joinPartyDate,
                          String joinWorkDate, String health, String specialty, String workNatureId, String personNatureId, String highEduId, String allDayEduId, String allDaySchool,
                          String jobEduId, String jobSchool, String nowPost, String nowPostDate, String area, String streetId, String residentId, String photoIds, String reward,
                          String familyAddress, String phone, String zipCode, String studyJSON, String workJSON, String familyJSON, Integer shoulder, String shoulderDet,
                          String general, String cardId){
        Person person = null;
        if(StringUtils.isNotEmpty(keyId)){
            person = personService.get(keyId);
        }else{
            person = new Person();
            person.setCompany(user.getCompany());
            person.setCreater(user);

            if(StringUtils.isEmpty(general) || "after".equals(general)){
                person.setGeneralDict(getGeneralAfter());
            }else{
                person.setGeneralDict(getGeneralBefore());
            }
        }
        person.setName(name);
        person.setGender(gender);
        person.setBirthday(DataUtil.StringToDate(birthday));
        person.setNation(dictItemService.get(nationId));
        person.setOrigin(origin);
        person.setBirthPlace(birthPlace);
        person.setJoinPartyDate(DataUtil.StringToDate(joinPartyDate));
        person.setJoinWorkDate(DataUtil.StringToDate(joinWorkDate));
        person.setHealth(health);
        person.setSpecialty(specialty);
        person.setWorkNature(dictItemService.get(workNatureId));
        person.setPersonNature(dictItemService.get(personNatureId));
        person.setHighEdu(dictItemService.get(highEduId));
        person.setAllDayEdu(dictItemService.get(allDayEduId));
        person.setAllDaySchool(allDaySchool);
        person.setJobEdu(dictItemService.get(jobEduId));
        person.setJobSchool(jobSchool);
        person.setNowPost(nowPost);
        person.setNowPostDate(DataUtil.StringToDate(nowPostDate));
        person.setArea(area);
        person.setStreet(dictItemService.get(streetId));
        if(StringUtils.isEmpty(residentId)) residentId="";
        person.setResident(residentService.get(residentId));
        person.setReward(reward);
        person.setFamilyAddress(familyAddress);
        person.setPhone(phone);
        person.setZipCode(zipCode);
        person.setShoulder(shoulder == null ? 0 : shoulder);
        person.setShoulderDet(shoulderDet);
        person.setCardId(cardId);
        person.setShoulder1(0);

        //保存头像
        if(StringUtils.isNotEmpty(photoIds)){
            List<FileManage> fileManageList = new ArrayList<FileManage>();
            for(String s:photoIds.split(",")){
                fileManageList.add(fileManagerService.get(s.trim()));
            }
            if(fileManageList.size()>0){
                person.setPhoto(fileManageList.get(0));
            }
        }

        //保存学习经历
        if(StringUtils.isNotEmpty(studyJSON)){
            JSONArray sJSON = JSONArray.fromObject(studyJSON);
            List<Study> studyList = new ArrayList<Study>();
            for(int i=0;i<sJSON.size();i++){
                String startDate = sJSON.getJSONObject(i).getString("startDate");
                String endDate = sJSON.getJSONObject(i).getString("endDate");
                String school = sJSON.getJSONObject(i).getString("school");
                String academicDegree = sJSON.getJSONObject(i).getString("academicDegree");
                if(StringUtils.isNotEmpty(startDate) || StringUtils.isNotEmpty(endDate) || StringUtils.isNotEmpty(school) || StringUtils.isNotEmpty(academicDegree)){
                    Study study = new Study();
                    study.setCreater(user);
                    study.setCompany(user.getCompany());
                    study.setStartDate(DataUtil.StringToDate(startDate));
                    study.setEndDate(DataUtil.StringToDate(endDate));
                    study.setSchool(school);
                    study.setAcademicDegree(academicDegree);
                    studyService.save(study);
                    studyList.add(study);
                }
            }
            person.setStudyList(studyList);
        }

        //保存工作经历
        if(StringUtils.isNotEmpty(workJSON)){
            JSONArray wJSON = JSONArray.fromObject(workJSON);
            List<Work> workList = new ArrayList<Work>();
            for(int i=0;i<wJSON.size();i++){
                String workStartDate = wJSON.getJSONObject(i).getString("workStartDate");
                String workEndDate = wJSON.getJSONObject(i).getString("workEndDate");
                String workDept = wJSON.getJSONObject(i).getString("workDept");
                String workPost = wJSON.getJSONObject(i).getString("workPost");
                String proveUser = wJSON.getJSONObject(i).getString("proveUser");
                if(StringUtils.isNotEmpty(workStartDate) || StringUtils.isNotEmpty(workEndDate) || StringUtils.isNotEmpty(workDept) || StringUtils.isNotEmpty(workPost) || StringUtils.isNotEmpty(proveUser)){
                    Work work = new Work();
                    work.setCreater(user);
                    work.setCompany(user.getCompany());
                    work.setWorkStartDate(DataUtil.StringToDate(workStartDate));
                    work.setWorkEndDate(DataUtil.StringToDate(workEndDate));
                    work.setWorkDept(workDept);
                    work.setWorkPost(workPost);
                    work.setProveUser(proveUser);
                    workService.save(work);
                    workList.add(work);
                }
            }
            person.setWorkList(workList);
        }

        //保存家庭信息
        if(StringUtils.isNotEmpty(familyJSON)){
            JSONArray fJSON = JSONArray.fromObject(familyJSON);
            List<Family> familyList = new ArrayList<Family>();
            for(int i=0;i<fJSON.size();i++){
                String nickName = fJSON.getJSONObject(i).getString("nickName");
                String familyName = fJSON.getJSONObject(i).getString("familyName");
                String familyBirthday = fJSON.getJSONObject(i).getString("familyBirthday");
                String politicalStatus = fJSON.getJSONObject(i).getString("politicalStatus");
                String familyEdu = fJSON.getJSONObject(i).getString("familyEdu");
                String familyJob = fJSON.getJSONObject(i).getString("familyJob");
                if(StringUtils.isNotEmpty(nickName) || StringUtils.isNotEmpty(familyName) || StringUtils.isNotEmpty(familyBirthday) || StringUtils.isNotEmpty(politicalStatus) || StringUtils.isNotEmpty(familyEdu) || StringUtils.isNotEmpty(familyJob)){
                    Family family = new Family();
                    family.setCreater(user);
                    family.setCompany(user.getCompany());
                    family.setNickName(nickName);
                    family.setFamilyName(familyName);
                    family.setFamilyBirthday(DataUtil.StringToDate(familyBirthday));
                    family.setPoliticalStatus(politicalStatus);
                    family.setFamilyEdu(familyEdu);
                    family.setFamilyJob(familyJob);
                    familyService.save(family);
                    familyList.add(family);
                }
            }
            person.setFamilyList(familyList);
        }


        return person;
    }

    /**
     * 保存操作
     */
    @RequestMapping(value = "save", method = RequestMethod.POST)
    public Object save(@CurrentUser User user, String keyId, String name, String gender, String birthday, String nationId, String origin, String birthPlace, String joinPartyDate,
                       String joinWorkDate, String health, String specialty, String workNatureId, String personNatureId, String highEduId, String allDayEduId, String allDaySchool,
                       String jobEduId, String jobSchool, String nowPost, String nowPostDate, String area, String streetId, String residentId, String photoIds, String reward,
                       String familyAddress, String phone, String zipCode, String studyJSON, String workJSON, String familyJSON, Integer shoulder, String shoulderDet,
                       String general, String cardId){
        Map<String, Object> rMap = new HashMap<String, Object>();
        Person person = setData(user,keyId,name,gender,birthday,nationId,origin,birthPlace,joinPartyDate,joinWorkDate,health,
                specialty,workNatureId,personNatureId,highEduId,allDayEduId,allDaySchool,jobEduId,jobSchool,nowPost,nowPostDate,
                area,streetId,residentId,photoIds,reward,familyAddress,phone,zipCode,studyJSON,workJSON,familyJSON,shoulder,
                shoulderDet,general, cardId);
        if(StringUtils.isNotEmpty(keyId)){
            personService.update(person);
            rMap.put("message", "更新成功");
        }else{
            personService.save(person, "com.fz.us.oa.core.entity.com.Person");
            rMap.put("message", "保存成功");
        }

        rMap.put("state", "1");
        rMap.put("keyId", keyId);
        return ajaxJson(rMap);
    }

    /**
     * 提交操作
     */
    @RequestMapping(value = "commit", method = RequestMethod.POST)
    public Object commit(@CurrentUser User user, String keyId, String name, String gender, String birthday, String nationId, String origin, String birthPlace, String joinPartyDate,
                         String joinWorkDate, String health, String specialty, String workNatureId, String personNatureId, String highEduId, String allDayEduId, String allDaySchool,
                         String jobEduId, String jobSchool, String nowPost, String nowPostDate, String area, String streetId, String residentId, String photoIds, String reward,
                         String familyAddress, String phone, String zipCode, String studyJSON, String workJSON, String familyJSON, String curDutyId, String comment, Integer shoulder,
                         String shoulderDet, String general, String cardId){
        Map<String, Object> rMap = new HashMap<String, Object>();
        Person person = setData(user, keyId, name, gender, birthday, nationId, origin, birthPlace, joinPartyDate, joinWorkDate, health,
                specialty, workNatureId, personNatureId, highEduId, allDayEduId, allDaySchool, jobEduId, jobSchool, nowPost, nowPostDate,
                area, streetId, residentId, photoIds, reward, familyAddress, phone, zipCode, studyJSON, workJSON, familyJSON, shoulder,
                shoulderDet, general, cardId);
        if (StringUtils.isNotEmpty(keyId)) {
            personService.approve(person, dutyService.get(curDutyId), comment);
        } else {
            personService.commit(person, "com.fz.us.oa.core.entity.com.Person", dutyService.get(curDutyId));
        }
        rMap.put("message", "提交成功");
        rMap.put("state", "1");
        rMap.put("keyId", keyId);
        return ajaxJson(rMap);
    }

    /**
     * 审批
     */
    @RequestMapping(value = "approve", method = RequestMethod.POST)
    public Object approve(@CurrentUser User user, String keyId, String curDutyId, String comment){
        Map<String,Object> rMap=new HashMap<String,Object>();
        Person person = personService.get(keyId);
        personService.approve(person, dutyService.get(curDutyId), comment);
        rMap.put("message","提交成功");
        rMap.put("state","1");
        rMap.put("keyId", keyId);
        return ajaxJson(rMap);
    }

    /**
     * 退回
     */
    @RequestMapping(value = "back", method = RequestMethod.POST)
    public Object back(@CurrentUser User user, String keyId, String curDutyId, String comment) {
        if (StringUtils.isNotEmpty(keyId)) {
            Person person = personService.get(keyId);
            personService.back(person, dutyService.get(curDutyId), comment);
        }
        Map<String,Object> rMap=new HashMap<String,Object>();
        rMap.put("message","退回成功");
        rMap.put("state","1");
        rMap.put("keyId", keyId);
        return ajaxJson(rMap);
    }

    /**
     * 否决
     */
    @RequestMapping(value = "deny", method = RequestMethod.POST)
    public Object deny(@CurrentUser User user, String keyId, String curDutyId, String comment) {
        if (StringUtils.isNotEmpty(keyId)) {
            Person person = personService.get(keyId);
            personService.deny(person, dutyService.get(curDutyId), comment);
        }
        Map<String,Object> rMap=new HashMap<String,Object>();
        rMap.put("message","否决成功");
        rMap.put("state","1");
        rMap.put("keyId", keyId);
        return ajaxJson(rMap);
    }

    /**
     * 统计汇总（书记）（换届前）
     */
    @RequestMapping(value = "summary", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String summary(@CurrentUser User user, Model model){
        DecimalFormat df = new DecimalFormat("0.00%");

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String, Object> rMap;

        int num01c = 0;
        int num02c = 0;
        int num03c = 0;
        int num04c = 0;
        int num05c = 0;
        int num06c = 0;
        int num09c = 0;
        int num11c = 0;
        int num13c = 0;
        int num15c = 0;
        int num16c = 0;
        int num17c = 0;
        int num18c = 0;
        int num19c = 0;
        int num20c = 0;
        int num23c = 0;
        int num25c = 0;
        int age = 0;
        int ageBeixuan = 0;

        List<DictItem> streetList = getDictItems(user, "street");
        for(DictItem street:streetList){
            int residentCount = personService.getResidentCountByStreet(street); //居民区党组织数

            Map<String, Object> params = new HashMap<String, Object>();
            params.put("street", street);
            params.put("state", BaseEnum.StateEnum.Enable);
            params.put("company", user.getCompany());
            params.put("generalDict", getGeneralBefore());
            List<Person> personList = personService.getList(params);


            int juminqu = 0; //居民区书记总人数
            int yijiantiao = 0; //一肩挑人数
            int niyijiantiao = 0; //拟一肩挑人数
            int nvxing = 0; //女性人数
            int allAge = 0; //年龄之和
            int dazhuan = 0; //大专以上学历人数
            int quanrizhi = 0; //全日制人数
            int tuixiufanpin = 0; //退休返聘人数

            int beixuan = 0; //备选书记人数
            int nimingque = 0; //拟明确备选居民区人数
            int weimingque = 0; //未明确备选居民区人数（备选书记人数 - 拟明确备选居民区人数）
            int shujiniyijiantiao = 0; //拟一肩挑人数
            int shujinvxing = 0; //书记女性人数
            int shujiAllAge = 0; //书记年龄总和
            int shujidazhuan = 0; //书记大专以上人数
            int shujiquanrizhi = 0; //书记全日制人数

            for(Person person:personList){

                if(person.getPersonNature()==null){
                    continue;
                }

                String thisPersonNature = person.getPersonNature()!=null?person.getPersonNature().getValue():""; //换届前数据

                if(person.getShoulder()==1){ //备选书记栏下的 拟一肩挑备选人数（查找所有的拟一肩挑）
                    if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("拟一肩挑备选")){
                        shujiniyijiantiao++;
                    }
                }

                if(!"shujihoubei".equals(thisPersonNature)){
                    //居民区书记人员
                    juminqu++;
//                    System.out.println(street.getName()+"："+person.getName());
                    if(person.getShoulder()==1){
                        if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("已一肩挑")){
                            yijiantiao++; //一肩挑人数
                        }
                        if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("拟一肩挑连任")){
                            niyijiantiao++; //拟一肩挑人数
                        }
                    }

                    if("女".equals(person.getGender())){ //女性人数
                        nvxing++;
                    }

                    allAge+=getSummaryAge(person.getBirthday());
                    age+=getSummaryAge(person.getBirthday());

                    String thisEdu = person.getHighEdu()!=null?person.getHighEdu().getValue():""; //大专以上人数
                    if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){
                        dazhuan++;
                        String allDayText = person.getAllDayEdu()!=null?person.getAllDayEdu().getValue():"";
                        if(allDayText.equals(thisEdu)){ //其中全日制人数
                            quanrizhi++;
                        }
                    }

                    if("tuixiufanpin".equals(thisPersonNature)){ //退休返聘人数
                        tuixiufanpin++;
                    }

                }else{
                    //备选书记人员
                    beixuan++;

                    if(person.getResident()!=null){
                        nimingque++; //拟明确备选居民区人数
                    }else{
                        weimingque++; //未明确备选居民区人数
                    }

                    if("女".equals(person.getGender())){ //女性人数
                        shujinvxing++;
                    }

                    shujiAllAge+=getSummaryAge(person.getBirthday());
                    ageBeixuan+=shujiAllAge;

                    String thisEdu = person.getHighEdu()!=null?person.getHighEdu().getValue():""; //大专以上人数
                    if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){
                        shujidazhuan++;
                        String allDayText = person.getAllDayEdu()!=null?person.getAllDayEdu().getValue():"";
                        if(allDayText.equals(thisEdu)){ //其中全日制人数
                            shujiquanrizhi++;
                        }
                    }
                }
            }

            rMap = new HashMap<String, Object>();
            rMap.put("streetName", street.getName());
            rMap.put("streetId", street.getId());
            rMap.put("residentCount", residentCount);
            num01c+=residentCount;

            rMap.put("niResidentCount", street.getDescription());
            num02c+=Integer.parseInt(street.getDescription());

            rMap.put("juminqushuji", juminqu);
            num03c+=juminqu;

            rMap.put("yijiantiao", yijiantiao);
            num04c+=yijiantiao;

            rMap.put("niyijiantiao", niyijiantiao);
            num05c+=niyijiantiao;

            rMap.put("nvxing", nvxing);
            num06c+=nvxing;

            rMap.put("dazhuan", dazhuan);
            num09c+=dazhuan;

            rMap.put("quanrizhi", quanrizhi);
            num11c+=quanrizhi;

            rMap.put("tuixiufanpin", tuixiufanpin);
            num13c+=tuixiufanpin;

            if(juminqu==0){
                rMap.put("nvxingBai", "0%");
                rMap.put("ageAvg", "0");
                rMap.put("dazhuanBai", "0%");
                rMap.put("quanrizhiBai", "0%");
                rMap.put("tuixiufanpinBai", "0%");
                rMap.put("huanjie", "0");
            }else{
                BigDecimal nvxingB = new BigDecimal(nvxing);
                BigDecimal juminquB = new BigDecimal(juminqu);
                BigDecimal bai = nvxingB.divide(juminquB,4,BigDecimal.ROUND_HALF_UP); //女性比例
                rMap.put("nvxingBai", df.format(bai));

                if(allAge==0){
                    rMap.put("ageAvg", "0");
                }else{
                    BigDecimal allAgeB = new BigDecimal(allAge);
                    BigDecimal ageAvg = allAgeB.divide(juminquB,2,BigDecimal.ROUND_HALF_UP);
                    rMap.put("ageAvg", ageAvg);
                }

                BigDecimal dazhuanB = new BigDecimal(dazhuan);
                BigDecimal dazhuanBai = dazhuanB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP); //大专比例
                rMap.put("dazhuanBai", df.format(dazhuanBai));

                BigDecimal quanrizhiB = new BigDecimal(quanrizhi);
                BigDecimal quanruzhiBai = quanrizhiB.divide(juminquB, 2, BigDecimal.ROUND_HALF_UP); //全日制比例
                rMap.put("quanrizhiBai", df.format(quanruzhiBai));

                BigDecimal tuixiufanpinB = new BigDecimal(tuixiufanpin);
                BigDecimal tuixiufanpinBai = tuixiufanpinB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP);
                rMap.put("tuixiufanpinBai", df.format(tuixiufanpinBai)); //退休返聘比例

                BigDecimal cB = new BigDecimal(residentCount).multiply(new BigDecimal(0.3));
                BigDecimal rs = tuixiufanpinB.subtract(cB);
                BigDecimal reC = rs.setScale(0, BigDecimal.ROUND_UP);
                int huan = Integer.parseInt(reC.toString());
                rMap.put("huanjie", huan<0?"0":huan); //换届人数 （退休返聘人数 - 街道下的居民区数量 * 0.3）

                num15c+=(Integer.parseInt(rs.setScale(0, BigDecimal.ROUND_UP).toString()));
            }


            rMap.put("beixuan", beixuan); //备选书记人数
            num16c+=beixuan;

            rMap.put("nimingque", nimingque); //拟明确备选书记数
            num17c+=nimingque;

            rMap.put("weimingque", weimingque); //为明确备选书记数
            num18c+=weimingque;

            rMap.put("shujiniyijiantiao", shujiniyijiantiao); //书记 拟一肩挑人数
            num19c+=shujiniyijiantiao;

            rMap.put("shujinvxing", shujinvxing); //女性书记人数
            num20c+=shujinvxing;

            rMap.put("shujidazhuan", shujidazhuan); //书记大专以上人数
            num23c+=shujidazhuan;

            rMap.put("shujiquanrizhi", shujiquanrizhi); //书记全日制人数
            num25c+=shujiquanrizhi;

            if(beixuan==0){
                rMap.put("shujinvxingBai", "0%");
                rMap.put("shujiAvgAge", "0");
                rMap.put("shujidazhuanBai", "0%");
                rMap.put("shujiquanrizhiBai", "0%");
            }else{
                BigDecimal beixuanB = new BigDecimal(beixuan);
                BigDecimal shujinvxingB = new BigDecimal(shujinvxing);
                BigDecimal shujinvxingBai = shujinvxingB.divide(beixuanB,4,BigDecimal.ROUND_HALF_UP);
                rMap.put("shujinvxingBai", df.format(shujinvxingBai)); //书记女性比例

                if(shujiAllAge==0){
                    rMap.put("shujiAvgAge", "0");
                }else{
                    BigDecimal shujiAllAgeB = new BigDecimal(shujiAllAge);
                    BigDecimal shujiAvgAge = shujiAllAgeB.divide(beixuanB,2,BigDecimal.ROUND_HALF_UP);
                    rMap.put("shujiAvgAge", shujiAvgAge); //书记平均年龄
                }

                BigDecimal shujidazhuanB = new BigDecimal(shujidazhuan);
                BigDecimal shujidazhuanBai = shujidazhuanB.divide(beixuanB,4,BigDecimal.ROUND_HALF_UP);
                rMap.put("shujidazhuanBai", df.format(shujidazhuanBai)); //书记大专比例

                BigDecimal shujiquanrizhiB = new BigDecimal(shujiquanrizhi);
                BigDecimal shujiquanrizhiBai = shujiquanrizhiB.divide(beixuanB,4,BigDecimal.ROUND_HALF_UP);
                rMap.put("shujiquanrizhiBai", df.format(shujiquanrizhiBai)); //书记全日制比例
            }
            dataRows.add(rMap);
        }


        //合计
        Map<String, Object> numData = new HashMap<String, Object>();
        numData.put("street", "合计（以拟参选数为基数）");
        numData.put("num01", num01c);
        numData.put("num02", num02c);
        numData.put("num03", num03c);
        numData.put("num04", num04c);
        numData.put("num05", num05c);
        numData.put("num06", num06c);
        numData.put("num07", num03c==0?"0%":df.format(new BigDecimal(num06c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        numData.put("num08", num03c == 0 ? "0" : new BigDecimal(age).divide(new BigDecimal(num03c), 2, BigDecimal.ROUND_UP));
        numData.put("num09", num09c);
        numData.put("num10", num03c==0?"0%":df.format(new BigDecimal(num09c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        numData.put("num11", num11c);
        numData.put("num12", num03c==0?"0%":df.format(new BigDecimal(num11c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        numData.put("num13", num13c);
        numData.put("num14", num03c==0?"0%":df.format(new BigDecimal(num13c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        numData.put("num15", num15c);

        numData.put("num16", num16c);
        numData.put("num17", num17c);
        numData.put("num18", num18c);
        numData.put("num19", num19c);
        numData.put("num20", num20c);
        numData.put("num21", num16c==0?"0%":df.format(new BigDecimal(num20c).divide(new BigDecimal(num16c),4,BigDecimal.ROUND_UP)));
        numData.put("num22", num16c == 0 ? "0" : new BigDecimal(ageBeixuan).divide(new BigDecimal(num16c), 2, BigDecimal.ROUND_UP));
        numData.put("num23", num23c);
        numData.put("num24", num16c==0?"0%":df.format(new BigDecimal(num23c).divide(new BigDecimal(num16c),4,BigDecimal.ROUND_UP)));
        numData.put("num25", num25c);
        numData.put("num26", num16c==0?"0%":df.format(new BigDecimal(num25c).divide(new BigDecimal(num16c),4,BigDecimal.ROUND_UP)));


        data.put("data", dataRows);
        model.addAttribute("data", data);
        model.addAttribute("numData", numData);

        return "/com/summary";
    }

    /**
     * 统计汇总（书记）（换届后）
     */
    @RequestMapping(value = "summaryAfter", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String summaryAfter(@CurrentUser User user, Model model){
        DecimalFormat df = new DecimalFormat("0.00%");

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String, Object> rMap;

        int num01c = 0;
        int num02c = 0;
        int num03c = 0;
        int num04c = 0;
        int num06c = 0;
        int num09c = 0;
        int num11c = 0;
        int num13c = 0;
        int age = 0;

        List<DictItem> streetList = getDictItems(user, "street");
        for(DictItem street:streetList){
            int residentCount = personService.getResidentCountByStreet(street); //居民区党组织数

            Map<String, Object> params = new HashMap<String, Object>();
            params.put("street", street);
            params.put("state", BaseEnum.StateEnum.Enable);
            params.put("company", user.getCompany());
            params.put("generalDict", getGeneralAfter());
            List<Person> personList = personService.getList(params);


            int juminqu = 0; //居民区书记总人数
            int yijiantiao = 0; //一肩挑人数
            int nvxing = 0; //女性人数
            int allAge = 0; //年龄之和
            int dazhuan = 0; //大专以上学历人数
            int quanrizhi = 0; //全日制人数
            int tuixiufanpin = 0; //退休返聘人数

            for(Person person:personList){

                if(person.getPersonNature()==null){ //换届后此字段（居民区）需要有值
                    continue;
                }

                String thisPersonNature = person.getPersonNature()!=null?person.getPersonNature().getValue():""; //换届后数据
                if(!"shujihoubei".equals(thisPersonNature)){
                    //居民区书记人员
                    juminqu++;
                    if(person.getShoulder()==1){
                        if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("已一肩挑")){
                            yijiantiao++; //一肩挑人数
                        }
                    }

                    if("女".equals(person.getGender())){ //女性人数
                        nvxing++;
                    }

                    allAge+=getSummaryAge(person.getBirthday());
                    age+=getSummaryAge(person.getBirthday());

                    String thisEdu = person.getHighEdu()!=null?person.getHighEdu().getValue():""; //大专以上人数
                    if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){
                        dazhuan++;
                        String allDayText = person.getAllDayEdu()!=null?person.getAllDayEdu().getValue():"";
                        if(allDayText.equals(thisEdu)){ //其中全日制人数
                            quanrizhi++;
                        }
                    }

                    if("tuixiufanpin".equals(thisPersonNature)){ //退休返聘人数
                        tuixiufanpin++;
                    }

                }
            }

            rMap = new HashMap<String, Object>();
            rMap.put("streetName", street.getName());
            rMap.put("streetId", street.getId());
            rMap.put("residentCount", residentCount);
            num01c+=residentCount;

            rMap.put("niResidentCount", street.getDescription());
            num02c+=Integer.parseInt(street.getDescription());

            rMap.put("juminqushuji", juminqu);
            num03c+=juminqu;

            rMap.put("yijiantiao", yijiantiao);
            num04c+=yijiantiao;

            rMap.put("nvxing", nvxing);
            num06c+=nvxing;

            rMap.put("dazhuan", dazhuan);
            num09c+=dazhuan;

            rMap.put("quanrizhi", quanrizhi);
            num11c+=quanrizhi;

            rMap.put("tuixiufanpin", tuixiufanpin);
            num13c+=tuixiufanpin;

            if(juminqu==0){
                rMap.put("nvxingBai", "0%");
                rMap.put("ageAvg", "0");
                rMap.put("dazhuanBai", "0%");
                rMap.put("quanrizhiBai", "0%");
                rMap.put("tuixiufanpinBai", "0%");
                rMap.put("huanjie", "0");
                rMap.put("yijiantiaoBai", "0%");
            }else{
                BigDecimal nvxingB = new BigDecimal(nvxing);
                BigDecimal juminquB = new BigDecimal(juminqu);
                BigDecimal bai = nvxingB.divide(juminquB,4,BigDecimal.ROUND_HALF_UP); //女性比例
                rMap.put("nvxingBai", df.format(bai));

                if(allAge==0){
                    rMap.put("ageAvg", "0");
                }else{
                    BigDecimal allAgeB = new BigDecimal(allAge);
                    BigDecimal ageAvg = allAgeB.divide(juminquB,2,BigDecimal.ROUND_HALF_UP);
                    rMap.put("ageAvg", ageAvg);
                }

                BigDecimal dazhuanB = new BigDecimal(dazhuan);
                BigDecimal dazhuanBai = dazhuanB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP); //大专比例
                rMap.put("dazhuanBai", df.format(dazhuanBai));

                BigDecimal quanrizhiB = new BigDecimal(quanrizhi);
                BigDecimal quanruzhiBai = quanrizhiB.divide(juminquB, 2, BigDecimal.ROUND_HALF_UP); //全日制比例
                rMap.put("quanrizhiBai", df.format(quanruzhiBai));

                BigDecimal tuixiufanpinB = new BigDecimal(tuixiufanpin);
                BigDecimal tuixiufanpinBai = tuixiufanpinB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP);
                rMap.put("tuixiufanpinBai", df.format(tuixiufanpinBai)); //退休返聘比例

                BigDecimal yijiaotiaoB = new BigDecimal(yijiantiao);
                BigDecimal yijiantiaoBai = yijiaotiaoB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP);
                rMap.put("yijiantiaoBai", df.format(yijiantiaoBai)); //一肩挑比例
            }

            dataRows.add(rMap);
        }


        //合计
        Map<String, Object> numData = new HashMap<String, Object>();
        numData.put("street", "合计（以拟参选数为基数）");
        numData.put("num01", num01c);
        numData.put("num02", num02c);
        numData.put("num03", num03c);
        numData.put("num04", num04c);
        numData.put("num05", num03c==0?"0%":df.format(new BigDecimal(num04c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        numData.put("num06", num06c);
        numData.put("num07", num03c==0?"0%":df.format(new BigDecimal(num06c).divide(new BigDecimal(num03c), 4, BigDecimal.ROUND_UP)));
        numData.put("num08", num03c == 0 ? "0" : new BigDecimal(age).divide(new BigDecimal(num03c), 2, BigDecimal.ROUND_UP));
        numData.put("num09", num09c);
        numData.put("num10", num03c==0?"0%":df.format(new BigDecimal(num09c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        numData.put("num11", num11c);
        numData.put("num12", num03c==0?"0%":df.format(new BigDecimal(num11c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        numData.put("num13", num13c);
        numData.put("num14", num03c==0?"0%":df.format(new BigDecimal(num13c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));


        data.put("data",dataRows);
        model.addAttribute("data", data);
        model.addAttribute("numData", numData);

        return "/com/summaryAfter";
    }

    /**
     * 统计汇总（书记）（换届前后对比）
     */
    @RequestMapping(value = "summaryCompare", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String summaryCompare(@CurrentUser User user, Model model){
        DecimalFormat df = new DecimalFormat("0.00%");

        DictItem generalBeforeDict = getGeneralBefore();
        DictItem generalAfterDict = getGeneralAfter();
        String generalBedoreValue = generalBeforeDict!=null?generalBeforeDict.getValue():"";
        String generalAfterValue = generalAfterDict!=null?generalAfterDict.getValue():"";

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String, Object> rMap;

        int num01c = 0;
        int num02c = 0;
        int num03c = 0;
        int num04c = 0;
        int num05c = 0;
        int num07c = 0;
        int num09c = 0;
        int num11c = 0;
        int num15c = 0;
        int num17c = 0;
        int num19c = 0;
        int num21c = 0;
        int num23c = 0;
        int num25c = 0;
        int ageBefore = 0;
        int ageAfter = 0;

        List<DictItem> streetList = getDictItems(user, "street");
        for(DictItem street:streetList){
            int residentCount = personService.getResidentCountByStreet(street); //居民区党组织数

            Map<String, Object> params = new HashMap<String, Object>();
            params.put("street", street);
            params.put("state", BaseEnum.StateEnum.Enable);
            params.put("company", user.getCompany());
            List<Person> personList = personService.getList(params);


            int juminqu0 = 0; //总人数
            int yijiantiao0 = 0; //一肩挑人数
            int nvxing0 = 0; //女性人数
            int allAge0 = 0; //年龄之和
            int dazhuan0 = 0; //大专以上学历人数
            int quanrizhi0 = 0; //全日制人数
            int tuixiufanpin0 = 0; //退休返聘人数

            int juminqu1 = 0; //总人数
            int yijiantiao1 = 0; //一肩挑人数
            int nvxing1 = 0; //女性人数
            int allAge1 = 0; //年龄之和
            int dazhuan1 = 0; //大专以上学历人数
            int quanrizhi1 = 0; //全日制人数
            int tuixiufanpin1 = 0; //退休返聘人数

            for(Person person:personList){

                String thisPersonNature = person.getPersonNature()!=null?person.getPersonNature().getValue():"";

                //换届前
                if(person.getPersonNature()!=null && !"shujihoubei".equals(thisPersonNature) && person.getGeneralDict()!=null && generalBedoreValue.equals(person.getGeneralDict().getValue())){
                    juminqu0++;
                    if(person.getShoulder()==1){
                        if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("已一肩挑")){
                            yijiantiao0++; //一肩挑人数
                        }
                    }

                    if("女".equals(person.getGender())){ //女性人数
                        nvxing0++;
                    }

                    allAge0+=getSummaryAge(person.getBirthday());
                    ageBefore+=getSummaryAge(person.getBirthday());

                    String thisEdu = person.getHighEdu()!=null?person.getHighEdu().getValue():""; //大专以上人数
                    if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){
                        dazhuan0++;
                        String allDayText = person.getAllDayEdu()!=null?person.getAllDayEdu().getValue():"";
                        if(allDayText.equals(thisEdu)){ //其中全日制人数
                            quanrizhi0++;
                        }
                    }

                    if("tuixiufanpin".equals(thisPersonNature)){ //退休返聘人数
                        tuixiufanpin0++;
                    }
                }


                // -------------------------------------------------------------------------------------------


                //换届后
                if(person.getPersonNature()!=null && !"shujihoubei".equals(thisPersonNature) && person.getGeneralDict()!=null && generalAfterValue.equals(person.getGeneralDict().getValue())){
                    juminqu1++;
                    if(person.getShoulder()==1){
                        if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("已一肩挑")){
                            yijiantiao1++; //一肩挑人数
                        }
                    }

                    if("女".equals(person.getGender())){ //女性人数
                        nvxing1++;
                    }

                    allAge1+=getSummaryAge(person.getBirthday());
                    ageAfter+=getSummaryAge(person.getBirthday());

                    String thisEdu = person.getHighEdu()!=null?person.getHighEdu().getValue():""; //大专以上人数
                    if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){
                        dazhuan1++;
                        String allDayText = person.getAllDayEdu()!=null?person.getAllDayEdu().getValue():"";
                        if(allDayText.equals(thisEdu)){ //其中全日制人数
                            quanrizhi1++;
                        }
                    }

                    if("tuixiufanpin".equals(thisPersonNature)){ //退休返聘人数
                        tuixiufanpin1++;
                    }
                }
            }

            rMap = new HashMap<String, Object>();
            rMap.put("streetName", street.getName());
            rMap.put("streetId", street.getId());
            rMap.put("residentCount", residentCount);
            num01c+=residentCount;

            rMap.put("niResidentCount", street.getDescription());
            num02c+=Integer.parseInt(street.getDescription());

            rMap.put("juminqu0", juminqu0);
            rMap.put("juminqu1", juminqu1);
            num03c+=juminqu0;
            num04c+=juminqu1;

            rMap.put("yijiantiao0", yijiantiao0);
            rMap.put("yijiantiao1", yijiantiao1);
            num05c+=yijiantiao0;
            num07c+=yijiantiao1;

            rMap.put("nvxing0", nvxing0);
            rMap.put("nvxing1", nvxing1);
            num09c+=nvxing0;
            num11c+=nvxing1;

            rMap.put("dazhuan0", dazhuan0);
            rMap.put("dazhuan1", dazhuan1);
            num15c+=dazhuan0;
            num17c+=dazhuan1;

            rMap.put("quanrizhi0", quanrizhi0);
            rMap.put("quanrizhi1", quanrizhi1);
            num19c+=quanrizhi0;
            num21c+=quanrizhi1;

            rMap.put("tuixiufanpin0", tuixiufanpin0);
            rMap.put("tuixiufanpin1", tuixiufanpin1);
            num23c+=tuixiufanpin0;
            num25c+=tuixiufanpin1;


            if(juminqu0==0){
                rMap.put("nvxingBai0", "0%");
                rMap.put("ageAvg0", "0");
                rMap.put("dazhuanBai0", "0%");
                rMap.put("quanrizhiBai0", "0%");
                rMap.put("tuixiufanpinBai0", "0%");
                rMap.put("yijiantiaoBai0", "0%");
            }else{
                BigDecimal nvxingB = new BigDecimal(nvxing0);
                BigDecimal juminquB = new BigDecimal(juminqu0);
                BigDecimal bai = nvxingB.divide(juminquB,4,BigDecimal.ROUND_HALF_UP); //女性比例
                rMap.put("nvxingBai0", df.format(bai));

                if(allAge0==0){
                    rMap.put("ageAvg", "0");
                }else{
                    BigDecimal allAgeB = new BigDecimal(allAge0);
                    BigDecimal ageAvg = allAgeB.divide(juminquB,2,BigDecimal.ROUND_HALF_UP);
                    rMap.put("ageAvg0", ageAvg); //平均年龄
                }

                BigDecimal dazhuanB = new BigDecimal(dazhuan0);
                BigDecimal dazhuanBai = dazhuanB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP); //大专比例
                rMap.put("dazhuanBai0", df.format(dazhuanBai));

                BigDecimal quanrizhiB = new BigDecimal(quanrizhi0);
                BigDecimal quanruzhiBai = quanrizhiB.divide(juminquB, 2, BigDecimal.ROUND_HALF_UP); //全日制比例
                rMap.put("quanrizhiBai0", df.format(quanruzhiBai));

                BigDecimal tuixiufanpinB = new BigDecimal(tuixiufanpin0);
                BigDecimal tuixiufanpinBai = tuixiufanpinB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP);
                rMap.put("tuixiufanpinBai0", df.format(tuixiufanpinBai)); //退休返聘比例

                BigDecimal yijiaotiaoB = new BigDecimal(yijiantiao0);
                BigDecimal yijiantiaoBai = yijiaotiaoB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP);
                rMap.put("yijiantiaoBai0", df.format(yijiantiaoBai)); //一肩挑比例
            }

            if(juminqu1==0){
                rMap.put("nvxingBai1", "0%");
                rMap.put("ageAvg1", "0");
                rMap.put("dazhuanBai1", "0%");
                rMap.put("quanrizhiBai1", "0%");
                rMap.put("tuixiufanpinBai1", "0%");
                rMap.put("yijiantiaoBai1", "0%");
            }else{
                BigDecimal nvxingB = new BigDecimal(nvxing1);
                BigDecimal juminquB = new BigDecimal(juminqu1);
                BigDecimal bai = nvxingB.divide(juminquB,4,BigDecimal.ROUND_HALF_UP); //女性比例
                rMap.put("nvxingBai1", df.format(bai));

                if(allAge1==0){
                    rMap.put("ageAvg1", "0");
                }else{
                    BigDecimal allAgeB = new BigDecimal(allAge1);
                    BigDecimal ageAvg = allAgeB.divide(juminquB,2,BigDecimal.ROUND_HALF_UP);
                    rMap.put("ageAvg1", ageAvg); //平均年龄
                }

                BigDecimal dazhuanB = new BigDecimal(dazhuan1);
                BigDecimal dazhuanBai = dazhuanB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP); //大专比例
                rMap.put("dazhuanBai1", df.format(dazhuanBai));

                BigDecimal quanrizhiB = new BigDecimal(quanrizhi1);
                BigDecimal quanruzhiBai = quanrizhiB.divide(juminquB, 2, BigDecimal.ROUND_HALF_UP); //全日制比例
                rMap.put("quanrizhiBai1", df.format(quanruzhiBai));

                BigDecimal tuixiufanpinB = new BigDecimal(tuixiufanpin1);
                BigDecimal tuixiufanpinBai = tuixiufanpinB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP);
                rMap.put("tuixiufanpinBai1", df.format(tuixiufanpinBai)); //退休返聘比例

                BigDecimal yijiaotiaoB = new BigDecimal(yijiantiao1);
                BigDecimal yijiantiaoBai = yijiaotiaoB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP);
                rMap.put("yijiantiaoBai1", df.format(yijiantiaoBai)); //一肩挑比例
            }

            dataRows.add(rMap);
        }
        data.put("data",dataRows);

        //合计
        Map<String, Object> numData = new HashMap<String, Object>();
        numData.put("street", "合计（以拟参选数为基数）");
        numData.put("num01", num01c);
        numData.put("num02", num02c);
        numData.put("num03", num03c);
        numData.put("num04", num04c);
        BigDecimal beforeNum = new BigDecimal(num03c); //换届前总人数
        BigDecimal afterNum = new BigDecimal(num04c); //换届后总人数
        numData.put("num05", num05c);
        numData.put("num06", num03c==0?"0%":df.format(new BigDecimal(num05c).divide(beforeNum,4,BigDecimal.ROUND_UP)));
        numData.put("num07", num07c);
        numData.put("num08", num04c==0?"0%":df.format(new BigDecimal(num07c).divide(afterNum,4,BigDecimal.ROUND_UP)));
        numData.put("num09", num09c);
        numData.put("num10", num03c==0?"0%":df.format(new BigDecimal(num09c).divide(beforeNum,4,BigDecimal.ROUND_UP)));
        numData.put("num11", num11c);
        numData.put("num12", num04c==0?"0%":df.format(new BigDecimal(num11c).divide(afterNum,4,BigDecimal.ROUND_UP)));
        numData.put("num13", num03c == 0 ? "0" : new BigDecimal(ageBefore).divide(beforeNum, 2, BigDecimal.ROUND_UP));
        numData.put("num14", num04c == 0 ? "0" : new BigDecimal(ageAfter).divide(afterNum, 2, BigDecimal.ROUND_UP));
        numData.put("num15", num15c);
        numData.put("num16", num03c==0?"0%":df.format(new BigDecimal(num15c).divide(beforeNum,4,BigDecimal.ROUND_UP)));
        numData.put("num17", num17c);
        numData.put("num18", num04c==0?"0%":df.format(new BigDecimal(num17c).divide(afterNum, 4, BigDecimal.ROUND_UP)));
        numData.put("num19", num19c);
        numData.put("num20", num03c==0?"0%":df.format(new BigDecimal(num19c).divide(beforeNum,4,BigDecimal.ROUND_UP)));
        numData.put("num21", num21c);
        numData.put("num22", num04c==0?"0%":df.format(new BigDecimal(num21c).divide(afterNum,4,BigDecimal.ROUND_UP)));
        numData.put("num23", num23c);
        numData.put("num24", num03c==0?"0%":df.format(new BigDecimal(num23c).divide(beforeNum,4,BigDecimal.ROUND_UP)));
        numData.put("num25", num25c);
        numData.put("num26", num04c==0?"0%":df.format(new BigDecimal(num25c).divide(afterNum,4,BigDecimal.ROUND_UP)));

        model.addAttribute("data", data);
        model.addAttribute("numData", numData);

        return "/com/summaryCompare";
    }


    /**
     * 统计总汇（主任）
     */
    @RequestMapping(value = "directorSummary", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String directorSummary(@CurrentUser User user, Model model){
        DecimalFormat df = new DecimalFormat("0.00%");

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String, Object> rMap;

        List<DictItem> streetList = getDictItems(user, "street");
        for(DictItem street:streetList){

            Map<String, Object> params = new HashMap<String, Object>();
            params.put("street", street);
            params.put("state", BaseEnum.StateEnum.Enable);
            params.put("company", user.getCompany());
            List<Director> directorList = directorService.getList(params); //此街道上的所有人

            rMap = new HashMap<String, Object>();
            int residentCount = personService.getResidentCountByStreet(street);
            rMap.put("residentCount", street.getDescription()); //固定数量
            int directorCount = directorList.size();
            rMap.put("personCount", directorCount);//实有人数
            rMap.put("street", street.getName()); //街道
            rMap.put("streetId", street.getId()); //街道id
            rMap.put("streetNum", residentCount); //居委会数

            int yijiantiao = 0; //一肩挑人数
            int niyijiantiao = 0; //拟一肩挑人数
            int nvxing = 0; //女性人数
            int ageCount = 0; //年龄之和
            int jiuye = 0; //就业年龄段人数
            int dazhuan = 0; //大专以上人数
            int quanrizhi = 0; //全日制人数
            int dangyuan = 0; //中共党员人数（有入党时间的话就是党员）
            int dangyuannan = 0; //党员 男
            int dangyuannv = 0; //党员 女

            for(Director director:directorList){

                ageCount+=getSummaryAge(director.getBirthday());

                if(director.getShoulder()==1){
                    if(director.getShoulderDet().contains("已一肩挑")){
                        yijiantiao++;
                    }
                    if(director.getShoulderDet().contains("拟一肩挑备选")){
                        niyijiantiao++;
                    }
                }

                if("女".equals(director.getGender())){
                    nvxing++;
                    if(getAge(director.getBirthday())<50){
                        jiuye++;
                    }
                }else{
                    if(getAge(director.getBirthday())<60){
                        jiuye++;
                    }
                }

                String thisEdu = director.getHighEdu()!=null?director.getHighEdu().getValue():""; //大专以上人数
                if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){
                    dazhuan++;
                }

                if(director.getAllDayEdu()!=null){ //其中：全日制人数
                    quanrizhi++;
                }

                if(director.getJoinPartyDate()!=null){
                    dangyuan++;
                    if("男".equals(director.getGender())){
                        if(getAge(director.getBirthday())<57){
                            dangyuannan++;
                        }
                    }else{
                        if(getAge(director.getBirthday())<52){
                            dangyuannv++;
                        }
                    }
                }
            }

            rMap.put("yijiantiao", yijiantiao); //一肩挑人数
            rMap.put("niyijiantiao", niyijiantiao); //拟一肩挑人数
            rMap.put("nvxing", nvxing); //女性人数
            rMap.put("jiuye", jiuye); //就业年龄段人数
            rMap.put("dazhuan", dazhuan); //大专以上人数
            rMap.put("quanrizhi", quanrizhi); //全日制人数
            rMap.put("dangyuan", dangyuan); //中共党员人数
            rMap.put("dangyuannan", dangyuannan); //党员男
            rMap.put("dangyuannv", dangyuannv); //党员女

            if(directorCount==0){
                rMap.put("ageAvg", 0);
                rMap.put("jiuyeBi", "0%");
                rMap.put("dazhuanBi", "0%");
                rMap.put("quanrizhiBi", "0%");
                rMap.put("nvxingBi", "0%");
                rMap.put("dangyuanBi", "0%");
            }else{
                BigDecimal all = new BigDecimal(directorCount);
                rMap.put("nvxingBi", df.format(new BigDecimal(nvxing).divide(all,4,BigDecimal.ROUND_UP))); //女性比例
                rMap.put("ageAvg", new BigDecimal(ageCount).divide(all, 2, BigDecimal.ROUND_UP)); //平均年龄
                rMap.put("jiuyeBi", df.format(new BigDecimal(jiuye).divide(all, 4, BigDecimal.ROUND_UP))); //就业年龄段人数
                rMap.put("dazhuanBi", df.format(new BigDecimal(dazhuan).divide(all,4,BigDecimal.ROUND_UP))); //大专比例
                rMap.put("quanrizhiBi", df.format(new BigDecimal(quanrizhi).divide(all,4,BigDecimal.ROUND_UP))); //全日制比例
                rMap.put("dangyuanBi", df.format(new BigDecimal(dangyuan).divide(all,4,BigDecimal.ROUND_UP))); //中共党员比例
            }

            //党员比例
            if(dangyuan==0){
                rMap.put("dangyuannanBi", "0%");
                rMap.put("dangyuannvBi", "0%");
            }else{
                BigDecimal dangyuanAll = new BigDecimal(dangyuan);
                rMap.put("dangyuannanBi", df.format(new BigDecimal(dangyuannan).divide(dangyuanAll,4,BigDecimal.ROUND_UP))); //党员男比例
                rMap.put("dangyuannvBi", df.format(new BigDecimal(dangyuannv).divide(dangyuanAll,4,BigDecimal.ROUND_UP))); //党员女比例
            }

            dataRows.add(rMap);
        }
        model.addAttribute("data", dataRows);

        return "/com/directorSummary";
    }

    /**
     * 打开街道里的居民区数据页面
     */
    @RequestMapping(value = "openStreet", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String openStreet(@CurrentUser User user, Model model, String streetId){
        if(StringUtils.isNotEmpty(streetId)){
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("state", BaseEnum.StateEnum.Enable);
            params.put("company", user.getCompany());
            params.put("street", dictItemService.get(streetId));
            List<Resident> residentList = residentService.getList(params);
            model.addAttribute("residentList", residentList);
        }
        return "/com/resident_dialog_open";
    }

    //获取备选书记系统字典
    public DictItem beiXuan(){
        DictItem beixuan = null;
        Dict personNature = dictService.getByValue("personNature");
        if(personNature!=null){
            beixuan = dictItemService.getByValue(personNature.getId(), "shujihoubei");
        }
        return beixuan;
    }

    /**
     * 根据街道打开人员列表 性别分类
     */
    @RequestMapping(value = "openPerson", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String openPerson(@CurrentUser User user, Model model, String streetId, Integer isBeiXuan, String type){
        if(StringUtils.isNotEmpty(streetId)){

            DictItem beixuan = beiXuan();

            List<Rule> rules = new ArrayList<Rule>();
            rules.add(RuleHelper.eq("street", dictItemService.get(streetId)));
            rules.add(RuleHelper.isNotNull("personNature"));

            if("before".equals(type)){
                rules.add(RuleHelper.eq("generalDict", getGeneralBefore()));
            }else{
                rules.add(RuleHelper.eq("generalDict", getGeneralAfter()));
            }

            if(isBeiXuan==1){
                rules.add(RuleHelper.eq("personNature", beixuan));
            }else{
                rules.add(RuleHelper.ne("personNature", beixuan));
            }

            List<Person> personList = personService.findPerson(rules);

            List<Map<String, Object>> personList0 = new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> personList1 = new ArrayList<Map<String, Object>>();
            Map<String, Object> rMap;
            for(Person person:personList){
                rMap = new HashMap<String, Object>();
                rMap.put("id", person.getId());
                rMap.put("name", person.getName());
                rMap.put("age", getSummaryAge(person.getBirthday()));
                if("女".equals(person.getGender())){
                    personList0.add(rMap);
                }else{
                    personList1.add(rMap);
                }
            }

            model.addAttribute("personList0", personList0);
            model.addAttribute("personList1", personList1);
        }
        return "/com/person_list_dialog";
    }

    /**
     * 根据街道打开人员列表 大专分类
     */
    @RequestMapping(value = "openDaZhuanPerson", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String openDaZhuanPerson(@CurrentUser User user, Model model, String streetId, Integer isBeiXuan, String type){
        DictItem beixuan = beiXuan();
        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("street", dictItemService.get(streetId)));
        rules.add(RuleHelper.isNotNull("personNature"));

        if("before".equals(type)){
            rules.add(RuleHelper.eq("generalDict", getGeneralBefore()));
        }else{
            rules.add(RuleHelper.eq("generalDict", getGeneralAfter()));
        }

        if(isBeiXuan==1){
            rules.add(RuleHelper.eq("personNature", beixuan));
        }else{
            rules.add(RuleHelper.ne("personNature", beixuan));
        }

        List<Person> personList = personService.findPerson(rules);

        List<Map<String, Object>> personList0 = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> personList1 = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;
        for(Person person:personList){
            rMap = new HashMap<String, Object>();
            rMap.put("id", person.getId());
            rMap.put("name", person.getName());
            rMap.put("edu", person.getHighEdu()!=null?person.getHighEdu().getName():"");
            rMap.put("age", person.getGender());
            String thisEdu = person.getHighEdu()!=null ? person.getHighEdu().getValue() : "";
            if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){

                if(person.getAllDayEdu()!=null && thisEdu.equals(person.getAllDayEdu().getValue())){
                    rMap.put("nature", "全日制教育");
                }else if(person.getJobEdu()!=null && thisEdu.equals(person.getJobEdu().getValue())){
                    rMap.put("nature", "在职教育");
                }else{
                    rMap.put("nature", "");
                }

                personList0.add(rMap);
            }else{
                personList1.add(rMap);
            }
        }

        model.addAttribute("personList0", personList0);
        model.addAttribute("personList1", personList1);

        return "/com/person_daZhuan_dialog";
    }

    /**
     * 根据街道打开人员列表 退休返聘
     */
    @RequestMapping(value = "openFanPinPerson", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String openFanPinPerson(@CurrentUser User user, Model model, String streetId, String type){
        DictItem fanPin = null;
        Dict personNature = dictService.getByValue("personNature");
        if(personNature!=null){
            fanPin = dictItemService.getByValue(personNature.getId(), "tuixiufanpin");
        }

        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("street", dictItemService.get(streetId)));
        rules.add(RuleHelper.isNotNull("personNature"));
        rules.add(RuleHelper.eq("personNature", fanPin));

        if("before".equals(type)){
            rules.add(RuleHelper.eq("generalDict", getGeneralBefore()));
        }else{
            rules.add(RuleHelper.eq("generalDict", getGeneralAfter()));
        }

        List<Person> personList = personService.findPerson(rules);

        List<Map<String, Object>> personList1 = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;
        for(Person person:personList){
            rMap = new HashMap<String, Object>();
            rMap.put("id", person.getId());
            rMap.put("name", person.getName());
            rMap.put("edu", person.getHighEdu()!=null ? person.getHighEdu().getName() : "");
            rMap.put("gender", person.getGender());
            rMap.put("age", getSummaryAge(person.getBirthday()));
            personList1.add(rMap);
        }
        model.addAttribute("personList", personList1);

        return "/com/person_fanPin_dialog";
    }

    /**
     * 根据街道打开人员列表 备选 拟明确未明确分类（只有换届前有这个）
     */
    @RequestMapping(value = "openNiMingQuePerson", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String openNiMingQuePerson(@CurrentUser User user, Model model, String streetId){
        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("street", dictItemService.get(streetId)));
        rules.add(RuleHelper.eq("personNature", beiXuan()));
        rules.add(RuleHelper.eq("generalDict", getGeneralBefore()));
        List<Person> personList = personService.findPerson(rules);

        List<Map<String, Object>> personList0 = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> personList1 = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;
        for(Person person:personList){
            rMap = new HashMap<String, Object>();
            rMap.put("id", person.getId());
            rMap.put("name", person.getName());
            rMap.put("edu", person.getHighEdu()!=null?person.getHighEdu().getName():"");
            rMap.put("gender", person.getGender());
            if(person.getResident()!=null){
                personList0.add(rMap);
            }else{
                personList1.add(rMap);
            }
        }
        model.addAttribute("personList0", personList0);
        model.addAttribute("personList1", personList1);

        return "/com/person_niMingQue_dialog";
    }

    /**
     * 打开一肩挑人员 （书记）
     */
    @RequestMapping(value = "openYijiantiao", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String openYijiantiao(@CurrentUser User user, Model model, String streetId, Integer isBeiXuan, String type){
        DictItem beixuan = beiXuan();
        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("shoulder", 1));
        rules.add(RuleHelper.eq("street", dictItemService.get(streetId)));
        rules.add(RuleHelper.isNotNull("personNature"));

        if("before".equals(type)){
            rules.add(RuleHelper.eq("generalDict", getGeneralBefore())); //换届前
        }else{
            rules.add(RuleHelper.eq("generalDict", getGeneralAfter())); //换届后
        }

        if(isBeiXuan==1){
            rules.add(RuleHelper.eq("personNature", beixuan)); //备选书记
        }else{
            rules.add(RuleHelper.ne("personNature", beixuan)); //居民区书记
        }

        List<Person> personList = personService.findPerson(rules);

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;
        for(Person person:personList){
            if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("已一肩挑")){
                rMap = new HashMap<String, Object>();
                rMap.put("id", person.getId());
                rMap.put("name", person.getName());
                dataRows.add(rMap);
            }

        }

        model.addAttribute("personList", dataRows);
        return "/com/person_yijiantiao_dialog";
    }

    /**
     * 打开一肩挑人员 （主任）
     */
    @RequestMapping(value = "openZrYijiantiao", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String openZrYijiantiao(@CurrentUser User user, Model model, String streetId){
        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("street", dictItemService.get(streetId)));
        List<Director> personList = directorService.findPerson(rules);

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;
        for(Director person:personList){
            if(person.getShoulder()==1 && StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("已一肩挑")){
                rMap = new HashMap<String, Object>();
                rMap.put("id", person.getId());
                rMap.put("name", person.getName());
                dataRows.add(rMap);
            }
        }

        model.addAttribute("personList", dataRows);
        return "/com/person_yijiantiao_dialog";
    }

    /**
     * 打开拟一肩挑人员 （书记）（只有换届前有这个）
     */
    @RequestMapping(value = "openNiyijiantiao", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String openNiyijiantiao(@CurrentUser User user, Model model, String streetId, Integer isBeiXuan){
        DictItem beixuan = beiXuan();
        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("street", dictItemService.get(streetId)));
        rules.add(RuleHelper.eq("shoulder", 1));
        rules.add(RuleHelper.eq("generalDict", getGeneralBefore()));
        if(isBeiXuan==1){
//            rules.add(RuleHelper.eq("personNature", beixuan));
        }else{
            rules.add(RuleHelper.ne("personNature", beixuan));
        }
        List<Person> personList = personService.findPerson(rules);

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;
        for(Person person:personList){
            if(isBeiXuan==1){ //备选书记
                if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("拟一肩挑备选")){
                    rMap = new HashMap<String, Object>();
                    rMap.put("id", person.getId());
                    rMap.put("name", person.getName());
                    dataRows.add(rMap);
                }
            }else{ //居民区书记
                if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("拟一肩挑连任")){
                    rMap = new HashMap<String, Object>();
                    rMap.put("id", person.getId());
                    rMap.put("name", person.getName());
                    dataRows.add(rMap);
                }
            }

        }

        model.addAttribute("personList", dataRows);
        return "/com/person_yijiantiao_dialog";
    }

    /**
     * 打开拟一肩挑人员 （主任）
     */
    @RequestMapping(value = "openZrNiyijiantiao", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String openZrNiyijiantiao(@CurrentUser User user, Model model, String streetId){
        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("street", dictItemService.get(streetId)));
        rules.add(RuleHelper.eq("shoulder", 1));
        List<Director> personList = directorService.findPerson(rules);

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;
        for(Director person:personList){
            if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("拟一肩挑备选")){
                rMap = new HashMap<String, Object>();
                rMap.put("id", person.getId());
                rMap.put("name", person.getName());
                dataRows.add(rMap);
            }

        }

        model.addAttribute("personList", dataRows);
        return "/com/person_yijiantiao_dialog";
    }


    /**
     * 最终的 打开人员信息（从统计明细里的dialog里打开的）
     */
    @RequestMapping(value = "personInfo", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
    public String personInfo(@CurrentUser User user, Model model, String keyId){
        if(StringUtils.isNotEmpty(keyId)){
            Person person = personService.get(keyId);
            if(person!=null){
                model.addAttribute("person", person);
                model.addAttribute("isDirector", 0);

                List<Study> studyList = new ArrayList<Study>();
                for(Study study:person.getStudyList()){
                    if("Enable".equals(study.getState().name())){
                        studyList.add(study);
                    }
                }
                List<Work> workList = new ArrayList<Work>();
                for(Work work:person.getWorkList()){
                    if("Enable".equals(work.getState().name())){
                        workList.add(work);
                    }
                }
                model.addAttribute("workList", workList);
                model.addAttribute("studyList", studyList);

            }else{
                Director director = directorService.get(keyId);
                model.addAttribute("person", director);
                model.addAttribute("isDirector", 1);

                List<Study> studyList = new ArrayList<Study>();
                for(Study study:director.getStudyList()){
                    if("Enable".equals(study.getState().name())){
                        studyList.add(study);
                    }
                }
                List<Work> workList = new ArrayList<Work>();
                for(Work work:director.getWorkList()){
                    if("Enable".equals(work.getState().name())){
                        workList.add(work);
                    }
                }
                model.addAttribute("workList", workList);
                model.addAttribute("studyList", studyList);

            }

        }

        return "/com/person_info";
    }


    @RequestMapping(value = "init2015", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public Object init2015(){
        DictItem huanjiehou = dictItemService.get("8a8a8ba762a80ccd0162a8ca33650002");
        List<Person> personList = personService.getAll();
        int i=0;
        int length=personList.size();
        for(Person old:personList){
            System.out.println("正在处理第" + i + "个，一共有" + length+"个");
            Person person = new Person();
            person.setGeneralDict(huanjiehou);
            person.setName(old.getName());
            person.setCompany(old.getCompany());
            person.setGender(old.getGender());
            person.setBirthday(old.getBirthday());
            person.setNation(old.getNation());
            person.setOrigin(old.getOrigin());
            person.setBirthPlace(old.getBirthPlace());
            person.setJoinPartyDate(old.getJoinPartyDate());
            person.setHealth(old.getHealth());
            person.setTxtTecDuty(old.getTxtTecDuty());
            person.setSpecialty(old.getSpecialty());
            person.setWorkNature(old.getWorkNature());
//            person.setPersonNature(old.getPersonNature1());
            person.setHighEdu(old.getHighEdu());
            person.setAllDayEdu(old.getAllDayEdu());
            person.setAllDaySchool(old.getAllDaySchool());
            person.setJobEdu(old.getJobEdu());
            person.setJobSchool(old.getJobSchool());
            person.setNowPost(old.getNowPost());
            person.setNowPostDate(old.getNowPostDate());
            person.setArea(old.getArea());
            person.setStreet(old.getStreet());
            person.setPhoto(old.getPhoto());
            person.setReward(old.getReward());
//            person.setResident(old.getResident1());
//            person.setShoulder(old.getShoulder1());
//            person.setShoulderDet(old.getShoulderDet1());
            person.setFamilyAddress(old.getFamilyAddress());
            person.setPhone(old.getPhone());
            person.setZipCode(old.getZipCode());

            List<Study> studyList = new ArrayList<Study>();
            for(Study study:old.getStudyList()){
                Study newStudy = new Study();
                newStudy.setStartDate(study.getStartDate());
                newStudy.setEndDate(study.getEndDate());
                newStudy.setSchool(study.getSchool());
                newStudy.setAcademicDegree(study.getAcademicDegree());
                studyService.save(newStudy);
                studyList.add(newStudy);
            }
            person.setStudyList(studyList);

            List<Work> workList = new ArrayList<Work>();
            for(Work work:old.getWorkList()){
                Work newWork = new Work();
                newWork.setWorkStartDate(work.getWorkStartDate());
                newWork.setWorkEndDate(work.getWorkEndDate());
                newWork.setWorkDept(work.getWorkDept());
                newWork.setWorkPost(work.getWorkPost());
                newWork.setProveUser(work.getProveUser());
                workService.save(newWork);
                workList.add(newWork);
            }
            person.setWorkList(workList);

            List<Family> familyList = new ArrayList<Family>();
            for(Family family:old.getFamilyList()){
                Family newFamily = new Family();
                newFamily.setNickName(family.getNickName());
                newFamily.setFamilyName(family.getFamilyName());
                newFamily.setFamilyBirthday(family.getFamilyBirthday());
                newFamily.setPoliticalStatus(family.getPoliticalStatus());
                newFamily.setFamilyEdu(family.getFamilyEdu());
                newFamily.setFamilyJob(family.getFamilyJob());
                familyService.save(newFamily);
                familyList.add(newFamily);
            }
            person.setFamilyList(familyList);

            personService.commit(person, "com.fz.us.oa.core.entity.com.Person", dutyService.get("4028818b6261ae52016261b42fb20002"));
        }
        return ajaxJson(resultService.success("初始化成功"));
    }

}
